import tkinter as tk
from tkinter import messagebox
import random

# 全局变量，用于记录送花次数
flower_count = 0
required_flowers = 100  # 需要送花的次数

def show_flower(canvas):
    """在随机位置显示一朵花"""
    x = random.randint(50, 450)
    y = random.randint(50, 450)
    canvas.create_oval(x-10, y-10, x+10, y+10, fill="pink", outline="red")
    canvas.create_text(x, y, text="🌸", font=("Arial", 16))

def send_flower():
    """点击按钮送花"""
    global flower_count
    flower_count += 1
    show_flower(canvas)
    flower_label.config(text=f"送花次数：{flower_count}/{required_flowers}")

    if flower_count == required_flowers:
        messagebox.showinfo("表白成功", "恭喜你！小美答应了你的表白！")
        reset_game()

def reset_game():
    """重置游戏"""
    global flower_count
    flower_count = 0
    canvas.delete("all")
    flower_label.config(text=f"送花次数：{flower_count}/{required_flowers}")

# 创建主窗口
root = tk.Tk()
root.title("小美表白送花")
root.geometry("500x600")

# 标题标签
title_label = tk.Label(root, text="小美表白送花", font=("Helvetica", 20), fg="purple")
title_label.pack(pady=20)

# 显示送花次数的标签
flower_label = tk.Label(root, text=f"送花次数：0/{required_flowers}", font=("Arial", 16))
flower_label.pack(pady=10)

# 创建画布，用于显示花朵
canvas = tk.Canvas(root, width=500, height=400, bg="lightyellow")
canvas.pack()

# 送花按钮
send_button = tk.Button(root, text="送花", font=("Arial", 14), width=10, height=2, command=send_flower)
send_button.pack(pady=20)

# 退出按钮
exit_button = tk.Button(root, text="退出", font=("Arial", 14), width=10, height=2, command=root.quit)
exit_button.pack(pady=10)

# 运行主循环
root.mainloop()
